import { Router } from 'express';
import jetValidator from 'jet-validator';
import { IReq, IRes } from './types/express/misc';
import Paths from '../constants/Paths';
import EpicRoutes from './EpicRoutes';


// **** Variables **** //

const apiRouter = Router();
const validate = jetValidator(); //https://github.com/seanpmaxwell/jet-validator

const epicRouter = Router();
// 设置Epic接口全部跨域
epicRouter.use((req: IReq<object>, res: IRes, next) => {  
  res.header('Access-Control-Allow-Origin', '*');
  res.header('Access-Control-Allow-Headers', 'Content-Type');
  res.header('Access-Control-Allow-Methods', '*');
  res.header('Content-Type', 'application/json;charset=utf-8');

  next();
});

epicRouter.post(
  Paths.EPIC.Login,
  validate('username', 'password', 'domain'),
  EpicRoutes.login,
);

apiRouter.use(Paths.EPIC.Base, epicRouter);

export default apiRouter;
